# Contributor: Edward E. <develinthedetail@gmail.com>

_realname=libheif
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.10.0
pkgrel=3
pkgdesc="HEIF image decoder/encoder library and tools (mingw-w64)"
arch=('any')
url="https://github.com/strukturag/libheif"
license=('LGPL3' 'MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-aom"
         "${MINGW_PACKAGE_PREFIX}-dav1d"
         "${MINGW_PACKAGE_PREFIX}-libde265"
         "${MINGW_PACKAGE_PREFIX}-libjpeg-turbo"
         "${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-libwinpthread-git"
         "${MINGW_PACKAGE_PREFIX}-rav1e"
         "${MINGW_PACKAGE_PREFIX}-x265")
options=('strip')
source=("https://github.com/strukturag/libheif/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        "001-fix-pkgconfig-provide-includedir.patch"
        "002-pkg-config-add-dav1d-rav1e.patch")
sha256sums=('ad5af1276f341277dc537b0d19a4193e0833c247b2aacb936e0c5494141533ae'
            'b782444a8f2c3f23c3b57e6e0a25ebe1313656aeeb72fad2335b1c6ee4b90a0b'
            '06f4a4c1b966f19ba3177de895f4c8a7879a94668ab9f593d0c63b7094b5c637')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "${srcdir}/001-fix-pkgconfig-provide-includedir.patch"

  # https://github.com/strukturag/libheif/pull/408/files
  patch -Np1 -i "${srcdir}/002-pkg-config-add-dav1d-rav1e.patch"

  autoreconf -fiv
}

build() {
  [[ -d "${srcdir}"/build-${MINGW_CHOST} ]] && rm -rf "${srcdir}"/build-${MINGW_CHOST}
  mkdir -p "${srcdir}"/build-${MINGW_CHOST} && cd "${srcdir}"/build-${MINGW_CHOST}

  CPPFLAGS+=" -DX265_API_IMPORTS=1"
  ../${_realname}-${pkgver}/configure \
    --disable-gdk-pixbuf \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --disable-go

  make
}

package() {
  cd "${srcdir}"/build-${MINGW_CHOST}
  make DESTDIR="${pkgdir}" install
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
